/**
 * 
 */
package agents.communication;

import jade.core.AID;
import jade.core.behaviours.OneShotBehaviour;
import jade.lang.acl.ACLMessage;
import es.ucm.fdi.agents.yellowPages.YellowPages;

import log.ContadorEventos;
import org.apache.log4j.Logger;

import agents.messages.MessageConstants;
import agents.persons.leader.LeaderAgent;
import log.Action;

/**
 * @author Elena
 *
 */
public class InitMessagesBehavior extends OneShotBehaviour{
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 8138697349076245286L;
	private AID[] listaAgentesEstudiantes;
	YellowPages paginasAmarillas;
	private Wait4AllPaths wait;
	
	static Logger logger = Logger.getLogger(CommunicationAgent.class);
	
	
	
	
	
	public void action() {
		paginasAmarillas = new YellowPages();
		listaAgentesEstudiantes = paginasAmarillas.buscarServicio(MessageConstants.SERV_GENERACION_COORDENADAS, myAgent);
		
		
		ACLMessage msg = new ACLMessage(ACLMessage.REQUEST);
		for (int i=0;i<listaAgentesEstudiantes.length;i++)
			msg.addReceiver(new AID(listaAgentesEstudiantes[i].getLocalName(),AID.ISLOCALNAME));
		msg.setContent(MessageConstants.MSJ_GENERA_COORDENADAS);
		myAgent.send(msg);

		logger.info(ContadorEventos.addEvent("STATIC",Action.ENVIAR_MSJ,"InitAgentBehavior"));

		wait = new Wait4AllPaths(myAgent,202);
		myAgent.addBehaviour(wait);
	}

}
